package com.hongxun.design.listeners;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.TextView;

import com.facebook.imagepipeline.core.ImagePipelineFactory;
import com.hongxun.design.MyApp;
import com.hongxun.design.R;
import com.hongxun.design.activitys.AppSettingsActivity;
import com.hongxun.design.activitys.AuthorizationActivity;
import com.hongxun.design.activitys.ChoiceModelActivity;
import com.hongxun.design.activitys.CollectActivity;
import com.hongxun.design.activitys.CreateProjectActivity;
import com.hongxun.design.activitys.CreateProjectAttributeCodeActivity;
import com.hongxun.design.activitys.DotDesignActivity;
import com.hongxun.design.activitys.EncyclopediasActivity;
import com.hongxun.design.activitys.ExperienceActivity;
import com.hongxun.design.activitys.FacingEachActivity;
import com.hongxun.design.activitys.LogFillActivity;
import com.hongxun.design.activitys.MultiselectActivity;
import com.hongxun.design.activitys.MyNewsActivity;
import com.hongxun.design.activitys.OfflineMapActivity;
import com.hongxun.design.activitys.ProjectFootPrintActivity;
import com.hongxun.design.activitys.ProjectNavigationActivity;
import com.hongxun.design.activitys.ProjectSelfCheckActivity;
import com.hongxun.design.activitys.ReconnaissanceActivity;
import com.hongxun.design.activitys.SelectDelectProjectActivity;
import com.hongxun.design.activitys.SelectProjectActivity;
import com.hongxun.design.activitys.UserInfoSetActivity;
import com.hongxun.design.bean.PhotoBean;
import com.hongxun.design.bean.PhotoGraphBean;
import com.hongxun.design.bean.ProjectItemBean;
import com.hongxun.design.bean.SetPointInfItemBean;
import com.hongxun.design.constant.Constant;
import com.hongxun.design.jungong.activity.Mainactivity_jg;
import com.hongxun.design.jungong.activity.ProItemInfoActivity;
import com.hongxun.design.mytools.IntentToActivity;
import com.hongxun.design.mytools.MString;
import com.hongxun.design.mytools.MyLog;
import com.hongxun.design.mytools.ShardPreferencesTool;
import com.hongxun.design.mytools.ToastShow;
import com.hongxun.design.ui.switchview.SwitchView;
import com.hongxun.design.utils.PopwindowUtil;
import com.hongxun.design.utils.clearcache.DataCleanManager;
import com.hongxun.design.utils.selfupdate.UpdateUtil;
import com.zbar.lib.CaptureActivity;

import java.io.File;
import java.util.Map;


/**
 * Created by zerdoor_pc on 2016/4/29.
 */
public class ListenerSet {

    /**
     * 首页创建项目功能——点击跳转事件*
     */
    public static View.OnClickListener founction_createprojects = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (MyApp.activity == null) return;
            if (MyApp.userInfo.getOrg_type().equalsIgnoreCase("11")) {
                ToastShow.showShort(MyApp.activity, "业主单位人员不能创建项目!");
                return;
            }

            IntentToActivity.intent(MyApp.activity, CreateProjectActivity.class);
            if (PopwindowUtil.titlePopup != null) PopwindowUtil.titlePopup.dismiss();
        }
    };


    /**
     * 面对面快传功能——点击跳转事件*
     */
    public static View.OnClickListener founction_facetoface = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (MyApp.activity == null) return;
            IntentToActivity.intent(MyApp.activity, FacingEachActivity.class);
            if (PopwindowUtil.titlePopup != null) PopwindowUtil.titlePopup.dismiss();
        }
    };
    /**
     * 扫一扫功能——点击跳转事件*
     */
    public static View.OnClickListener founction_scantoscan = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (MyApp.activity == null) return;
            Bundle bun = new Bundle();
            bun.putString(MString.TITLE, MString.ScanAndScan);
            bun.putString(MString.TYPE, MString.Scanproject);
            IntentToActivity.intent(MyApp.activity, CaptureActivity.class, bun);
            if (PopwindowUtil.titlePopup != null) PopwindowUtil.titlePopup.dismiss();
        }
    };

    /**
     * 同步功能——点击跳转事件*
     */
    public static View.OnClickListener founction_synchronization = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (MyApp.activity == null) return;
//            IntentToActivity.intent(MyApp.activity, SynchronizationActivity.class);
            Bundle bundle = new Bundle();
            bundle.putInt(MString.TYPE, Constant.NETLOAD);
            IntentToActivity.intent(MyApp.activity, SelectProjectActivity.class, bundle);
//            ToastShow.showShort(MyApp.activity, "暂未开通此功能");
        }
    };

    /**
     * 自检功能——点击跳转事件*
     */
    public static View.OnClickListener founction_selfcheck = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (MyApp.activity == null) return;
            IntentToActivity.intent(MyApp.activity, ProjectSelfCheckActivity.class);
            //  ToastShow.showShort(MyApp.activity,"暂未开通此功能");
        }
    };

    /**
     * 项目踏设功能——点击跳转事件*
     */
    public static View.OnClickListener founction_SetFoot = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (MyApp.activity == null) return;
            MyApp.ChangeToNewProject(new ProjectItemBean());
            IntentToActivity.intent(MyApp.activity, ReconnaissanceActivity.class);
        }
    };

    /**
     * 典设库功能——点击跳转事件
     * 随手拍
     */
    public static View.OnClickListener founction_codelibrary = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (MyApp.activity == null) return;
            Bundle bundle = new Bundle();
            bundle.putString(MString.CODE, "2");
            IntentToActivity.intent(MyApp.activity, Mainactivity_jg.class, bundle);
        }
    };

    /**
     * 典设库功能——点击跳转事件
     * 项目典设设置
     */
    public static View.OnClickListener founction_codelibrary_project = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (MyApp.activity == null) return;
            Bundle bundle = new Bundle();
            String projectName = MyApp.currProject.getProject_name();
            bundle.putString(MString.CODE, "MATERIAL");
            bundle.putString(MString.project_name, projectName);
            IntentToActivity.intent(MyApp.activity, ChoiceModelActivity.class, bundle);
        }
    };

    /**
     * 统计分析功能——点击跳转事件
     * 材料组装-详情
     */
    public static View.OnClickListener founction_statistical_analysis = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (MyApp.activity == null) return;
            Bundle bundle = new Bundle();
            bundle.putString(MString.CODE, "1");
            IntentToActivity.intent(MyApp.activity, Mainactivity_jg.class, bundle);
        }
    };


    /**
     * 统计分析功能——点击跳转事件
     * 材料组装
     */
    public static View.OnClickListener founction_proiteminfo = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (MyApp.activity == null) return;
            IntentToActivity.intent(MyApp.activity, ProItemInfoActivity.class);
        }
    };

    /**
     * 工作日志功能——点击跳转事件*
     */
    public static View.OnClickListener founction_logfill = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (MyApp.activity == null) return;
            //ToastShow.showShort(MyApp.activity, "暂未开通此功能");
            IntentToActivity.intent(MyApp.activity, LogFillActivity.class);
//            ToastShow.showShort(MyApp.activity, "暂未开通此功能");
        }
    };

    /**
     * 项目足迹功能——点击跳转事件*
     */
    public static View.OnClickListener founction_projectfoot = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (MyApp.activity == null) return;
            IntentToActivity.intent(MyApp.activity, ProjectFootPrintActivity.class);
        }
    };
    /**
     * 收藏功能——点击跳转事件*
     */
    public static View.OnClickListener founction_collect = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (MyApp.activity == null) return;
            IntentToActivity.intent(MyApp.activity, CollectActivity.class);
        }
    };
    /**
     * 个人设置功能——点击跳转事件*
     */
    public static View.OnClickListener founction_userset = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (MyApp.activity == null) return;
            IntentToActivity.intent(MyApp.activity, UserInfoSetActivity.class);
        }
    };

    /**
     * 我的经验功能——点击跳转事件*
     */
    public static View.OnClickListener founction_experience = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (MyApp.activity == null) return;
            IntentToActivity.intent(MyApp.activity, ExperienceActivity.class);
//            try {
//                ZipUtil.upZipFile(ClipPathUtil.getAPPPath() + MyApp.openIdent+"/ProjectStage_4167.zip", ClipPathUtil.getAPPPath() + MyApp.openIdent);
//
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
        }
    };
    /**
     * 我的消息功能——点击跳转事件*
     */
    public static View.OnClickListener founction_mynews = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (MyApp.activity == null) return;
            IntentToActivity.intent(MyApp.activity, MyNewsActivity.class);
//            ToastShow.showShort(MyApp.activity, "暂未开通此功能");
            try {
                //    ZipUtil.zipFolder(ClipPathUtil.getAPPPath()+MyApp.openIdent+"/ProjectStage_4167");
            } catch (Exception e) {
                e.printStackTrace();
            }


        }
    };

    /**
     * 应用设置功能——点击跳转事件*
     */
    public static View.OnClickListener founction_appsettings = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (MyApp.activity == null) return;
            IntentToActivity.intent(MyApp.activity, AppSettingsActivity.class);
            // MyApp.File.delete(new File(MyApp.activity.getFilesDir().getPath() + "/" + MyApp.openIdent));
        }
    };


    /**
     * 应用设置_清除缓存功能——点击事件*
     */
    public static View.OnClickListener founction_clearcache = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            File file = MyApp.activity.getCacheDir();
            try {
                ImagePipelineFactory.getInstance().getImagePipeline().clearMemoryCaches();//清除图片缓存
                if (!DataCleanManager.getCacheSize(file).equals("0B")) {
                    DataCleanManager.cleanInternalCache(MyApp.activity);
                    ((TextView) view.findViewById(R.id.appsetvalue_value)).setText(DataCleanManager.getCacheSize(file));
                } else {
                    ToastShow.showShort(MyApp.activity, "暂时没有缓存数据！");
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            MyLog.L(MString.SUCCESSED + "缓存路径=" + file.getPath());
//            MyApp.HTTP.GetDifferenceData(new Handler(), HttpStringUtil.SUCCESSED, 104.05860551388889, 30.570495625);

        }
    };

    /**
     * 应用设置_数据复制功能——点击事件*
     */
    public static View.OnClickListener founction_cachetosd = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            MyApp.File.copyDir();
            ToastShow.showShort(MyApp.activity, "复制成功！");
        }
    };
    /**
     * 应用设置_项目缓存文件夹删除功能——点击事件*
     */
    public static View.OnClickListener founction_delectcache = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            MyApp.File.delect(MyApp.activity.getFilesDir().getPath() + "/" + MyApp.openIdent);

            ToastShow.showShort(MyApp.activity, "删除成功！");
        }
    };
    /**
     * 应用设置_项目缓存文件夹删除功能(单个)——点击事件*
     */
    public static View.OnClickListener founction_delectprojectcache = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (MyApp.activity == null) return;
            IntentToActivity.intent(MyApp.activity, SelectDelectProjectActivity.class);
        }
    };
    /**
     * 应用设置_检查更新——点击事件*
     */
    public static View.OnClickListener founction_check = new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            UpdateUtil.getInstence().checkUpdate();
        }
    };

    /**
     * 应用设置_推送功能——点击事件*
     */
    public static SwitchView.OnStateChangedListener founction_push = new SwitchView.OnStateChangedListener() {
        @Override
        public void toggleToOn(View view) {
            MyApp.OpenPush();
            ((SwitchView) view).toggleSwitch(true);
            ShardPreferencesTool.saveshare(MyApp.activity, MString.PUSH, true);
        }

        @Override
        public void toggleToOff(View view) {
            MyApp.closePush();
            ((SwitchView) view).toggleSwitch(false);
            ShardPreferencesTool.saveshare(MyApp.activity, MString.PUSH, false);
        }
    };

    /**
     * 应用设置_离线功能——点击事件*
     */
    public static SwitchView.OnStateChangedListener founction_isoffline = new SwitchView.OnStateChangedListener() {
        @Override
        public void toggleToOn(View view) {
            ((SwitchView) view).toggleSwitch(true);//离线
            MyApp.ChangeToOffLine();

        }

        @Override
        public void toggleToOff(View view) {
            //((SwitchView) view).toggleSwitch(false);//在线
            MyApp.ChangeToOnLine((SwitchView) view);

        }
    };


//        new CompoundButton.OnCheckedChangeListener() {
//        @Override
//        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//            if (isChecked) {
//
//                if (!MyApp.mPushAgent.isEnabled()) {
//                    MyApp.mPushAgent.enable();
//                }
//            } else {
//                if (!MyApp.mPushAgent.isEnabled()) {
//                    MyApp.mPushAgent.disable();
//                }
//            }
//            ShardPreferencesTool.saveshare(MyApp.activity, MString.PUSH, isChecked);
//        }
//    };


    /**
     * 离线地图_更新功能——选择事件*
     */
    public static CompoundButton.OnCheckedChangeListener founction_updatemap = new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

            ShardPreferencesTool.saveshare(MyApp.activity, MString.WIFIUPDATE, isChecked);
        }
    };


    /**
     * 离线地图功能——点击事件*
     */
    public static View.OnClickListener founction_offlinemap = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (MyApp.activity == null) return;
            IntentToActivity.intent(MyApp.activity, OfflineMapActivity.class);
//            UPlayer.getIntence("upload/pic/20160804/1470273841212.amr").start();
//            http://218.6.173.17:8080/designpass/upload/pic/20160804/1470273841212.amr
            // MyApp.File.copyDir();
//          ToastShow.showShort(MyApp.activity, "暂未开通此功能");

        }
    };


    /**
     * 项目导航功能——点击事件*
     */
    public static View.OnClickListener founction_navigation = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (MyApp.activity == null) return;
            IntentToActivity.intent(MyApp.activity, ProjectNavigationActivity.class);

        }
    };
    /**
     * 购买授权功能——点击事件*
     */
    public static View.OnClickListener founction_authorization = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (MyApp.activity == null) return;
            IntentToActivity.intent(MyApp.activity, AuthorizationActivity.class);
            // MyApp.File.delect(MyApp.activity.getFilesDir().getPath() + "/" + MyApp.openIdent);
//            ToastShow.showShort(MyApp.activity, "暂未开通此功能");
        }
    };
    /**
     * 未开启功能点击跳转事件*
     */
    public static View.OnClickListener founction_no = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (MyApp.activity == null) return;
            ToastShow.showShort(MyApp.activity, "暂未开通此功能");

        }
    };

    /**
     * 关于我们点击跳转事件*
     */
    public static View.OnClickListener founction_aboutmy = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (MyApp.activity == null) return;
            //轮播点击
            Bundle bundle = new Bundle();
            bundle.putString(MString.TYPE, MString.Carouse);
            bundle.putString(MString.CODE, "1");
            //bundle.putString(MString.TITLE,b.title);
            bundle.putString(MString.TITLE, "关于我们");
            IntentToActivity.intent(MyApp.activity, EncyclopediasActivity.class, bundle);

        }
    };

    public static View.OnClickListener back = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            MyApp.activity.onBackPressed();
        }
    };

    public static View.OnClickListener codeSetClick = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            IntentToActivity.intent(MyApp.activity, CreateProjectAttributeCodeActivity.class);
        }
    };


    /**
     * 拍照点击打开系统相机*
     */
    public static View.OnClickListener getPhotoGrapOpenCameraListener(int type) {
        return new OpenCameraClick(type);
    }

    public static View.OnClickListener getPhotoGrapImageClickListener(int type) {
        return new ClickToActivity(type);
    }

    public static View.OnClickListener getPhotoGrapImageClickListener(int type, PhotoBean bean) {
        return new ClickToActivity(type, bean);
    }

    public static View.OnClickListener getPhotoGrapImageClickListener(int type, PhotoGraphBean bean) {
        return new ClickToActivity(type, bean);
    }

    /**
     * 点位设置删除定位点*
     */
    public static View.OnClickListener getDelectClicklinstener() {
        return new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (MString.getValueId(MyApp.currExploration.getExploration_id(), MyApp.currExploration.getUuid()).length() == 0) {
                    //IntentToActivity.intent(MyApp.activity, ReconnaissanceActivity.class);
                    MyApp.activity.onBackPressed();
                } else {
                    MyApp.delectExploration();
                }
                if (PopwindowUtil.titlePopup != null) PopwindowUtil.titlePopup.dismiss();
            }
        };

    }

    /**
     * 点击跳转到设计界面*
     */
    public static void getDesignClickListener(final Activity activity) {
        if (MyApp.currExploration.getPt_type().equals(Constant.LOCALPOINT)) {
            IntentToActivity.intent(activity, DotDesignActivity.class);
        }
    }

    /**
     * 设计界面item点击跳转*
     */
    public static View.OnClickListener getDesignItemClickListener(SetPointInfItemBean bean, String type, String codeset_id) {
        return new DesignItemClick(bean, type, codeset_id);
    }


    /**
     * 材料界面item点击跳转添加*
     */
    public static View.OnClickListener getAddMaterialItemClickListener(final String type, final Map<String, Object> map) {

        View.OnClickListener listener = new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Bundle bundle = new Bundle();
                bundle.putString(MString.TYPE, type);
                bundle.putString(MString.ERROR, String.valueOf(map.get("cid")));
                bundle.putString(MString.TRUE, String.valueOf(map.get("type")));
                IntentToActivity.intent(MyApp.activity, MultiselectActivity.class, bundle);
                if (PopwindowUtil.titlePopup != null) PopwindowUtil.titlePopup.dismiss();
            }
        };


        return listener;
    }

    /**
     * 点设添加材料弹出选择框
     */
    public static View.OnClickListener getMaterial_ModularItemClickListener(final int type, final Handler handler) {

        View.OnClickListener listener = new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                handler.sendEmptyMessage(type);
            }
        };


        return listener;
    }


}
